#!/usr/bin/env python
# -*- coding:utf-8 -*-


import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

def email(arg):
    msg = MIMEText(arg, 'plain', 'utf-8')
    msg['From'] = formataddr(["靳晓亮",'jinxiaoliang@wo.cn'])
    msg['To'] = formataddr(["jinxl",'42136639@qq.com'])
    msg['Subject'] = "天猫shuang11"

    server = smtplib.SMTP("smtp.wo.cn", 25)
    server.login("jinxiaoliang@wo.cn", "mima")
    server.sendmail('jinxiaoliang@wo.cn', ['42136639@qq.com',], msg.as_string())
    server.quit()

def end():
    if result is None:
        print '发送成功'
    else:
        print '发送失败'

if __name__=='__main__':
    cpu=100
    disk=100
    mem=100
    if cpu >90:
        cpu_alert=u'cpu故障'
        result=email(cpu_alert)
        #print result  ==> None 没有返回结果
        end()

    if disk >=100:
        disk_alert='disk故障'
        result=email(disk_alert)
        end()

    if mem>110:
        arg= 'mem'
        result=email(arg)
        end()